package com.oweight.sagacious.auth.server.infrastructure.util.user;

import com.oweight.sagacious.api.model.user.PersonInfo;
import com.oweight.sagacious.auth.common.util.jwt.IJWTInfo;
import com.oweight.sagacious.auth.common.util.jwt.JWTHelper;
import com.oweight.sagacious.auth.server.infrastructure.configuration.KeyConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author 周广明
 * @version v1 2019/10/21 16:31
 */
@Component
public class JwtTokenUtil {

    @Value("${jwt.expire}")
    private int expire;

    @Autowired
    private KeyConfiguration keyConfiguration;

    public String generateToken(IJWTInfo jwtInfo) throws Exception {
        return JWTHelper.generateToken(jwtInfo, keyConfiguration.getUserPriKey(), expire);
    }

    public String generateToken2(PersonInfo personInfo) throws Exception {
        return JWTHelper.generateToken2(personInfo, keyConfiguration.getUserPriKey(), expire);
    }

    public IJWTInfo getInfoFromToken(String token) throws Exception {
        return JWTHelper.getInfoFromToken(token, keyConfiguration.getUserPubKey());
    }


}
